package com.example.administrator.mymusic.Class;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Region;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * Created by Administrator on 2016/4/7.
 */


public class CercleView extends ImageView {
    Paint paint = null;
    Path path;

    public CercleView(Context context, AttributeSet attrs) {
        super(context, attrs);
//        initView(context);

        paint = new Paint();
        paint.setColor(Color.alpha(0));
        paint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onDraw(Canvas canvas) {

        float h = getMeasuredHeight();
        float w = getMeasuredWidth();
        if (path == null) {
            path = new Path();
            path.addCircle(w/2.0f, h/2.0f, (float) Math.min(w/2.0f, (h / 2.0)), Path.Direction.CCW);
            path.close();
        }
        canvas.drawCircle(w/2.0f, h/2.0f,  Math.min(w/2.0f, h / 2.0f), paint);
        int saveCount = canvas.getSaveCount();
        canvas.save();
//        canvas.setDrawFilter(mPaintFlagsDrawFilter);
        canvas.clipPath(path, Region.Op.REPLACE);
        canvas.drawColor(Color.WHITE);
        super.onDraw(canvas);
        canvas.restoreToCount(saveCount);
    }
}